package com.angel.domain.angeluser.aggregates;

import com.angel.domain.angeluser.entities.AngelUserInfo;
import com.angel.domain.angeluser.event.AngelUserRegisterEvent;
import com.angel.domain.angeluser.valueobjects.*;
import lombok.AllArgsConstructor;
import lombok.Getter;

/*
 * 更新关注微信公众号： 为了offer
 * @author parkin
 * @description  天使用户
 * @date 2021/11/13
 */
@Getter
@AllArgsConstructor
public class AngelUser {
    // 编号
    private AngelUserId angelUserId;
    // 用户信息
    private AngelUserInfo angelUserInfo;
    // 等级信息
    private AngelUserLevelInfo angelUserLevel;
    // 注册信息
    private CreateInfo createInfo;



    public AngelUser(WeChatInfo weChatInfo) {
       this(weChatInfo,
               new UserBasicInfo(
                       weChatInfo.getNickName(),
                       new HeadImage(weChatInfo.getAvatarUrl())
               )
       );
    }

    public AngelUser(WeChatInfo weChatInfo,UserBasicInfo userBasicInfo) {
        this.angelUserId = new AngelUserId();
        this.angelUserLevel = AngelUserLevelInfo.initUserLevel();
        this.angelUserInfo = new AngelUserInfo(
                this.angelUserId.getId(),
                weChatInfo,
                // 默认是微信昵称和头像
                userBasicInfo
        );
        this.createInfo = new CreateInfo(this.angelUserId);
    }

    public AngelUserRegisterEvent register() {
        AngelUserRegisterEvent angelUserRegisterEvent = new AngelUserRegisterEvent(
                AngelUserRegisterEvent.buildEventDate(this.getAngelUserId())
        );
        return angelUserRegisterEvent;
    }


}
